package com.cql.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class RestTemplateHystrixService {

    @Value("spring.application.name")
    String name;

    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "instanceInsoGetFail")
    public String ask(){
        return restTemplate.getForEntity("http://EUREKA-CLIENT-SERVICE/cql/rest/{name}", String.class, name).getBody();
    }

    private String instanceInsoGetFail() {
        return "error";
    }

    //=============
//    @Qualifier("hha")
//    @Autowired
//    InstanceClient instanceClient;
//
//    public String sayHello2(String name) {
//        return instanceClient.sayHello2(name);
//    }

}
